package Pages;
/*
 *  J2Egn version 2.6.28
 *  Author: Van Tan Tai 2010-2011
 *  static function
 */
import java.io.IOException;
import java.util.Vector;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class Static {
	
	public static void init(){
		try {
			imgNumber = Image.createImage("/numbers.png");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public static void destroy(){
		imgNumber =  null;
	}
	//number
	private static Image imgNumber = null;
	private static final byte NUM_HEIGHT = 14;
	private static final byte NUM_WIDTH = 12;
	
	public static void drawNumber(Graphics g,int iNum, int x, int y, int flag, boolean isMoney) {
		String str = String.valueOf(iNum) + (isMoney ? "$" : "");
		int left = x;
		int top = y;
		if(flag == 0) flag = Graphics.LEFT|Graphics.TOP;
		if((flag & Graphics.LEFT) == Graphics.LEFT){
			left = x;
		}
		if((flag & Graphics.RIGHT) == Graphics.RIGHT){
			left = x - (str.length()*NUM_WIDTH);
		}
		if((flag & Graphics.TOP) == Graphics.TOP){
			top = y;
		}
		if((flag & Graphics.BOTTOM) == Graphics.BOTTOM){
			top = y - NUM_HEIGHT;
		}
		if((flag & Graphics.HCENTER) == Graphics.HCENTER){
			left = x -  (str.length()*NUM_WIDTH) / 2;
		}
		if((flag & Graphics.VCENTER) == Graphics.VCENTER){
			top = y -  (NUM_HEIGHT) / 2;
		}
		
		if(iNum < 0)
			g.drawRegion(imgNumber, 12*NUM_WIDTH, 0, NUM_WIDTH, NUM_HEIGHT, 0, left, top, Graphics.TOP|Graphics.LEFT);
		int n = str.length() - (isMoney ? 1 : 0);
		for(int i=(iNum < 0 ? 1 : 0); i < n; i++){
			g.drawRegion(imgNumber, ((int)str.charAt(i)-48)*NUM_WIDTH, 0, NUM_WIDTH, NUM_HEIGHT, 0, left + (NUM_WIDTH* i), top, Graphics.TOP|Graphics.LEFT);
		}
		if(isMoney)	g.drawRegion(imgNumber, 10*NUM_WIDTH, 0, NUM_WIDTH, NUM_HEIGHT, 0, left + (NUM_WIDTH* (str.length()-1)), top, Graphics.TOP|Graphics.LEFT);
	}
	
	public static String[] split(String original,String separator)
	{
        Vector nodes=new Vector();
	    int index = original.indexOf(separator);
	    while(index>=0)
	    {
	        nodes.addElement( original.substring(0, index));
	        original = original.substring(index+separator.length());
	        index = original.indexOf(separator);
	    }
	    nodes.addElement( original );
	    String[] result = new String[ nodes.size() ];
	    if( nodes.size()>0 )
	    {
	        for(int loop=0; loop<nodes.size(); loop++)
	        {
	            result[loop] = (String)nodes.elementAt(loop);

	        }
	    }
	    return result;
	}

	
}
